package view.lcdui;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class PageListMain extends MIDlet {

	public PageListMain() {
		
	}

	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		
	}

	protected void pauseApp() {
		
	}

	protected void startApp() throws MIDletStateChangeException {
		
		// multiple choice List
		final PagableList list = new PagableList("List", List.MULTIPLE);
		
		Display.getDisplay(this).setCurrent(list);
		
		// 5 itens per page
		list.setMaxPerPage(5);
		// populate
		for(int i=0;i<13;i++) {
			list.append("Item "+(i+1), null);
		}
		
		// Adding 2 commands
		list.addCommand(new Command("OK", Command.OK, 2));
		//list.addCommand(new Command("ADD", Command.SCREEN, 2));
		
		list.setCommandListener(new CommandListener() {
			public void commandAction(Command cmd, Displayable d) {
				if(cmd.getLabel().equals("ADD")) {
					list.append("Item ??", null);
					return;
				}
				
				// Print all selected itens
				String[] sel = list.getAllSelected();
				for(int i=0; i<sel.length; i++)
					System.out.println("Selected:"+ sel[i]);				
			}
		});
	}

}